package com.zkzx.operation.api.controller.message;

import com.zkzx.common.constants.StatusEnum;
import com.zkzx.common.sitemail.command.AnnouncementCommand;
import com.zkzx.common.sitemail.model.AnnouncementVO;
import com.zkzx.operation.api.controller.BaseController;
import com.zkzx.operation.api.service.message.AnnouncementService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @author young Email:yanghui@zkraising.com
 * @description
 * @company 北京中科智兴物联科技有限公司 @版权所有
 * @since 2021年05月17日 10时35分
 */
@RestController
@Validated
@Api( tags="站内信-公告")
@RequestMapping(value = "/announcement")
public class AnnouncementController extends BaseController {

    @Autowired
    private AnnouncementService announcementService;

    @GetMapping
    @ResponseStatus(HttpStatus.OK)
    @ApiOperation(value = "获取发布公告详细信息", notes = "获取发布公告详细信息")
    public AnnouncementVO getByEnable() {
        return announcementService.get();
    }

    @PostMapping
    @ResponseStatus(HttpStatus.CREATED)
    @ApiOperation(value = "发布公告信息", notes = "发布公告信息")
    public void add(@RequestBody @Valid AnnouncementCommand command) {
        announcementService.addOrUpdate(command,super.getUserId());
    }


    @PutMapping("/{id}/disabled")
    @ResponseStatus(HttpStatus.OK)
    @ApiOperation(value = "下架公告", notes = "下架公告")
    public void disable(@PathVariable("id") Integer id) {
        announcementService.updateStatus(id, StatusEnum.DISABLE,super.getUserId());
    }




}
